package com.yanqu.backendweb.controller;

import com.alibaba.fastjson.JSON;
import com.yanqu.backendweb.service.AbsService;
import com.yanqu.backendweb.service.impl.RoleInfoServiceImpl;
import com.yanqu.backendweb.utils.Response;
import com.yanqu.backendweb.utils.SpringContext;
import com.yanqu.backendweb.utils.Utils;
import com.yanqu.backendweb.vo.RoleDetailVo;
import com.yanqu.backendweb.vo.RoleInfoVo;
import com.yanqu.backendweb.vo.RoleOtherVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import javax.validation.Valid;
import java.util.SortedMap;


/**
 * @author duli
 * @version 1.0
 * @date 2020/9/21 15:20
 * @Description 玩家信息查询
 */
@Controller
@RequestMapping("/player")
public class PlayerController {
    @Autowired
    private RoleInfoServiceImpl roleInfoService;
    /*
    * 获取玩家列表
    * */
    @RequestMapping("/getInfo")
    @ResponseBody
    public Response getInfo(String requestId, String sign, @RequestBody @Valid RoleInfoVo vo){
        SortedMap<String, Object> paramMap = JSON.parseObject(JSON.toJSONString(vo), SortedMap.class);
        paramMap.put("requestId",requestId);
        boolean flag= Utils.checkSign(paramMap,sign);
        if(flag){
            return roleInfoService.getInfo(vo);
        }else{
            return Response.singError();
        }
    }
    /*
     * 获取玩家详情
     * */
    @RequestMapping("/getDetail")
    @ResponseBody
    public Response getDetailInfo(String requestId, String sign, @RequestBody @Valid RoleDetailVo vo){
        SortedMap<String, Object> paramMap = JSON.parseObject(JSON.toJSONString(vo), SortedMap.class);
        paramMap.put("requestId",requestId);
        boolean flag=Utils.checkSign(paramMap,sign);
        if(flag){
            return roleInfoService.getDetailInfo(vo);
        }else{
            return Response.singError();
        }

    }
    /*
     * 获取玩家其它信息
     * */
    @RequestMapping("/getOtherInfo")
    @ResponseBody
    public Response getDetailInfo(String requestId, String sign, @RequestBody @Valid RoleOtherVo vo){
        SortedMap<String, Object> paramMap = JSON.parseObject(JSON.toJSONString(vo), SortedMap.class);
        paramMap.put("requestId",requestId);
        boolean flag=Utils.checkSign(paramMap,sign);
        if(flag){
            AbsService service = SpringContext.getBean(vo.getType().getService());
            return service.getOtherInfo(vo);
        }else{
            return Response.singError();
        }

    }
}
